import org.xenoserver.control.Defaults;
public class ParseDomainDestroy extends CommandParser {
- public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
- int domain_id = getIntParameter(args, 'n', 0);
- boolean force = getFlagParameter(args, 'f');
+ public void parse(Defaults d, LinkedList args)
+ throws ParseFailedException, CommandFailedException {
+ int domain_id = getIntParameter(args, 'n', 0);
+ boolean force = getFlagParameter(args, 'f');
- if (domain_id == 0) {
- throw new ParseFailedException("Expected -n<domain_id>");
+ if (domain_id == 0) {
+ throw new ParseFailedException("Expected -n<domain_id>");
+ }
+
+ String output = new CommandDomainDestroy(d, domain_id, force).execute();
+ if (output != null) {
+ System.out.println(output);
+ }
+ }
+
+ public String getName() {
+ return "destroy";
}
- String output = new CommandDomainDestroy(d, domain_id, force).execute();
- if ( output != null )
- System.out.println( output );
- }
-
- public String getName()
- {
- return "destroy";
- }
-
- public String getUsage()
- {
- return "[-f] [-n<domain_id>]";
- }
-
- public String getHelpText()
- {
- return
- "Destory the specified domain. -f forcibly destroys it.";
- }
+ public String getUsage() {
+ return "-n<domain_id> [-f]";
+ }
+
+ public String getHelpText() {
+ return "Destroy the specified domain. -f forcibly destroys it.";
+ }
}
import org.xenoserver.control.Domain;
public class ParseDomainList extends CommandParser {
+ public void parse(Defaults d, LinkedList args)
+ throws ParseFailedException, CommandFailedException {
+ CommandDomainList list = new CommandDomainList(d);
+ String output = list.execute();
+ if (output != null) {
+ System.out.println(output);
+ }
+
+ Domain[] domains = list.domains();
+
+ for (int loop = 0; loop < domains.length; loop++) {
+ System.out.println(
+ "id: " + domains[loop].id + " (" + domains[loop].name + ")");
+ System.out.println(" processor: " + domains[loop].processor);
+ System.out.println(" has cpu: " + domains[loop].cpu);
+ System.out.println(
+ " state: " + domains[loop].nstate + " " + domains[loop].state);
+ System.out.println(" mcu advance: " + domains[loop].mcu);
+ System.out.println(" total pages: " + domains[loop].pages);
+ }
+ }
+
+ public String getName() {
+ return "list";
+ }
+
+ public String getUsage() {
+ return "";
+ }
- public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
- CommandDomainList list = new CommandDomainList(d);
- String output = list.execute();
- if ( output != null )
- System.out.println( output );
- Domain[] domains = list.domains();
-
- for (int loop = 0; loop < domains.length; loop++)
- {
- System.out.println ("id: " + domains[loop].id +
- " (" + domains[loop].name+ ")");
- System.out.println (" processor: " + domains[loop].processor);
- System.out.println (" has cpu: " + domains[loop].cpu);
- System.out.println (" state: " + domains[loop].nstate + " " +
- domains[loop].state);
- System.out.println (" mcu advance: " + domains[loop].mcu);
- System.out.println (" total pages: " + domains[loop].pages);
+ public String getHelpText() {
+ return "List domain information and status.";
}
- }
-
- public String getName()
- {
- return "list";
- }
-
- public String getUsage()
- {
- return "";
- }
-
- public String getHelpText()
- {
- return
- "List domain information";
- }
}
import org.xenoserver.control.Defaults;
public class ParseDomainNew extends CommandParser {
+ public void parse(Defaults d, LinkedList args)
+ throws ParseFailedException, CommandFailedException {
+ String name = getStringParameter(args, 'n', d.domainName);
+ int size = getIntParameter(args, 'k', d.domainSizeKB);
+ String image = getStringParameter(args, 'i', d.domainImage);
+ String initrd = getStringParameter(args, 'r', d.domainInitRD);
+ int vifs = getIntParameter(args, 'v', d.domainVIFs);
+ String bargs = getStringParameter(args, 'a', d.args) + " ";
+ String root_dev = getStringParameter(args, 'd', d.rootDevice);
+ String nfs_root_path = getStringParameter(args, 'f', d.nwNFSRoot);
+ String nw_ip = getStringParameter(args, '4', d.nwIP);
+ String nw_gw = getStringParameter(args, 'g', d.nwGateway);
+ String nw_mask = getStringParameter(args, 'm', d.nwMask);
+ String nw_nfs_server = getStringParameter(args, 's', d.nwNFSServer);
+ String nw_host = getStringParameter(args, 'h', d.nwHost);
- public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
- String name = getStringParameter(args, 'n', d.domainName);
- int size = getIntParameter(args, 'k', d.domainSizeKB);
- String image = getStringParameter(args, 'i', d.domainImage);
- String initrd = getStringParameter (args, 'r', d.domainInitRD);
- int vifs = getIntParameter(args, 'v', d.domainVIFs);
- String bargs = getStringParameter (args, 'a', d.args) + " ";
- String root_dev = getStringParameter (args, 'd', d.rootDevice);
- String nfs_root_path = getStringParameter (args, 'f', d.nwNFSRoot);
- String nw_ip = getStringParameter (args, '4', d.nwIP);
- String nw_gw = getStringParameter (args, 'g', d.nwGateway);
- String nw_mask = getStringParameter (args, 'm', d.nwMask);
- String nw_nfs_server = getStringParameter (args, 's', d.nwNFSServer);
- String nw_host = getStringParameter (args, 'h', d.nwHost);
+ d.describe();
- d.describe();
+ CommandDomainNew c =
+ new CommandDomainNew(
+ d,
+ name,
+ size,
+ image,
+ initrd,
+ vifs,
+ bargs,
+ root_dev,
+ nfs_root_path,
+ nw_ip,
+ nw_gw,
+ nw_mask,
+ nw_nfs_server,
+ nw_host);
+ c.execute();
+ String[] output = c.output();
+ for (int i = 0; i < output.length; i++) {
+ System.out.println(output[i]);
+ }
+ }
- CommandDomainNew c = new CommandDomainNew(d, name, size, image, initrd, vifs,
- bargs, root_dev, nfs_root_path,
- nw_ip, nw_gw, nw_mask, nw_nfs_server, nw_host);
- c.execute();
- String[] output = c.output();
- for ( int i = 0; i < output.length; i++ )
- System.out.println( output[i] );
- }
+ public String getName() {
+ return "new";
+ }
- public String getName()
- {
- return "new";
- }
+ public String getUsage() {
+ return "[-n<domain_name>] [-k<size>] [-i<image>] [-v<num_vifs>] [-r<initrd>] [-d<root_device>] [-f<nfs_root>] [-s<nfs_boot_server>] [-4<ipv4_boot_address>] [-g<ipv4_boot_gateway>] [-m<ipv4_boot_netmask>] [-h<hostname>] [-a<args>]";
+ }
- public String getUsage()
- {
- return "[-n<domain_name>] [-k<size>] [-i<image>] [-v<num_vifs>] [-r<initrd>] [-d<root_device>] [-f<nfs_root>] [-s<nfs_boot_server>] [-4<ipv4_boot_address>] [-g<ipv4_boot_gateway>] [-m<ipv4_boot_netmask>] [-h<hostname>] [-a<args>]";
- }
-
- public String getHelpText()
- {
- return
- "Create a new domain. Note that most of the parameters will assume\n" +
- "default values: it should not be necessary to specify them all. See\n" +
- "domctl.xml for the current default settings.\n" +
- "\n" +
- "General command line options:\n" +
- " -n Domain name domain_name\n" +
- " -k Domain size (kb) domain_size_kb\n" +
- " -i Domain image name domain_image\n" +
- " -v Number of VIFs domain_vifs\n" +
- " -r InitRD (if required) domain_init_rd\n" +
- " -d Root device (e.g /dev/nfs, /dev/hda3) root_device\n" +
- " -a Additional boot parameters\n" +
- "\n" +
- "Networking options:\n" +
- " -f NFS root (if /dev/nfs specified) nw_nfs_root\n" +
- " -s NFS server nw_nfs_server\n" +
- " -4 Domain IPv4 address nw_ip\n" +
- " -g Domain gateway nw_gw\n" +
- " -m Domain net mask nw_mask\n" +
- " -h Domain hostname nw_host\n" +
- "\n" +
- "Parameters to -d, -f, -4, -g, -h can be specified as patterns into\n" +
- "which the allocated domain ID will be incorporated. e.g. for\n" +
- "domain 1 patterns would expand as follows:\n" +
- "\n" +
- " /dev/hda+ /dev/hda1\n" +
- " /dev/hda7+ /dev/hda8\n" +
- " 128.232.8.50+ 128.232.8.51\n" +
- "\n" +
- "Additionally, patterns for -4 -g -m can include an = which is\n" +
- "expanded to the corresponding setting from the calling domain.\n";
- }
+ public String getHelpText() {
+ return "Create a new domain. Note that most of the parameters will assume\n"
+ + "default values: it should not be necessary to specify them all. See\n"
+ + "domctl.xml for the current default settings.\n"
+ + "\n"
+ + "General command line options:\n"
+ + " -n Domain name domain_name\n"
+ + " -k Domain size (kb) domain_size_kb\n"
+ + " -i Domain image name domain_image\n"
+ + " -v Number of VIFs domain_vifs\n"
+ + " -r InitRD (if required) domain_init_rd\n"
+ + " -d Root device (e.g /dev/nfs, /dev/hda3) root_device\n"
+ + " -a Additional boot parameters\n"
+ + "\n"
+ + "Networking options:\n"
+ + " -f NFS root (if /dev/nfs specified) nw_nfs_root\n"
+ + " -s NFS server nw_nfs_server\n"
+ + " -4 Domain IPv4 address nw_ip\n"
+ + " -g Domain gateway nw_gw\n"
+ + " -m Domain net mask nw_mask\n"
+ + " -h Domain hostname nw_host\n"
+ + "\n"
+ + "Parameters to -d, -f, -4, -g, -h can be specified as patterns into\n"
+ + "which the allocated domain ID will be incorporated. e.g. for\n"
+ + "domain 1 patterns would expand as follows:\n"
+ + "\n"
+ + " /dev/hda+ /dev/hda1\n"
+ + " /dev/hda7+ /dev/hda8\n"
+ + " 128.232.8.50+ 128.232.8.51\n"
+ + "\n"
+ + "Additionally, patterns for -4 -g -m can include an = which is\n"
+ + "expanded to the corresponding setting from the calling domain.\n";
+ }
}
import org.xenoserver.control.Defaults;
public class ParseDomainStart extends CommandParser {
+ public void parse(Defaults d, LinkedList args)
+ throws ParseFailedException, CommandFailedException {
+ int domain_id = getIntParameter(args, 'n', 0);
- public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
- int domain_id = getIntParameter(args, 'n', 0);
-
- if (domain_id == 0) {
- throw new ParseFailedException("Expected -n<domain_id>");
+ if (domain_id == 0) {
+ throw new ParseFailedException("Expected -n<domain_id>");
+ }
+
+ String output = new CommandDomainStart(d, domain_id).execute();
+ if (output != null)
+ System.out.println(output);
+ }
+
+ public String getName() {
+ return "start";
}
- String output = new CommandDomainStart(d, domain_id).execute();
- if ( output != null )
- System.out.println( output );
- }
-
- public String getName()
- {
- return "start";
- }
-
- public String getUsage()
- {
- return "[-n<domain_id>]";
- }
-
- public String getHelpText()
- {
- return
- "Start the specified domain.";
- }
+ public String getUsage() {
+ return "-n<domain_id>";
+ }
+
+ public String getHelpText() {
+ return "Start the specified domain.";
+ }
}
import org.xenoserver.control.Defaults;
public class ParseDomainStop extends CommandParser {
+ public void parse(Defaults d, LinkedList args)
+ throws ParseFailedException, CommandFailedException {
+ int domain_id = getIntParameter(args, 'n', 0);
- public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
- int domain_id = getIntParameter(args, 'n', 0);
-
- if (domain_id == 0) {
- throw new ParseFailedException("Expected -n<domain_id>");
+ if (domain_id == 0) {
+ throw new ParseFailedException("Expected -n<domain_id>");
+ }
+
+ String output = new CommandDomainStop(d, domain_id).execute();
+ if (output != null)
+ System.out.println(output);
+ }
+
+ public String getName() {
+ return "stop";
}
- String output = new CommandDomainStop(d, domain_id).execute();
- if ( output != null )
- System.out.println( output );
- }
-
- public String getName()
- {
- return "stop";
- }
-
- public String getUsage()
- {
- return "[-n<domain_id>]";
- }
-
- public String getHelpText()
- {
- return
- "Stop the specified domain.";
- }
+ public String getUsage() {
+ return "-n<domain_id>";
+ }
+
+ public String getHelpText() {
+ return "Stop the specified domain.";
+ }
}
* Thrown when a command line could not be parsed.
*/
public class ParseFailedException extends Exception {
- public ParseFailedException() {
- super();
- }
+ public ParseFailedException(String message) {
+ super(message);
+ }
- public ParseFailedException(String message) {
- super(message);
- }
-
- public ParseFailedException(String message, Throwable cause) {
- super(message, cause);
- }
-
- public ParseFailedException(Throwable cause) {
- super(cause);
- }
+ public ParseFailedException(String message, Throwable cause) {
+ super(message, cause);
+ }
}
import org.xenoserver.control.Defaults;
public class ParseHelp extends CommandParser {
+ public void parse(Defaults d, LinkedList args) {
+ if (args == null || args.isEmpty()) {
+ System.out.println("Usage:");
+ Main.parser.printUsage(null);
+ } else {
+ System.out.print("xenctl ");
+ Main.parser.printHelpText(args);
+ }
- public void parse(Defaults d, LinkedList args) {
- if (args.size() == 0) {
- System.out.println("Usage:");
- Main.parser.printUsage(null);
- } else {
- System.out.print("xenctl ");
- Main.parser.printHelpText(args);
+ System.out.println("");
}
- System.out.println("");
- }
-
- public String getName()
- {
- return "help";
- }
+ public String getName() {
+ return "help";
+ }
- public String getUsage()
- {
- return "";
- }
+ public String getUsage() {
+ return "[<any command>]";
+ }
- public String getHelpText()
- {
- return "This message";
- }
+ public String getHelpText() {
+ return "This message, or if a command is specified, help for that command.";
+ }
}
public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
boolean force = getFlagParameter(args, 'f');
String partition_name = getStringParameter(args, 'p', "");
- String size = getStringParameter(args, 'c', "100M");
+ String size = getStringParameter(args, 'c', "128M");
- if (partition_name.equals(""))
+ if (partition_name.equals("")) {
throw new ParseFailedException("Expected -p<partition_name>");
+ }
long chunksize = Library.parseSize( size ) / Settings.SECTOR_SIZE;
- if ( chunksize <= 0 )
+ if ( chunksize <= 0 ) {
throw new CommandFailedException("Chunk size " + size + " is smaller than sector size.");
+ }
// Initialise the partition manager and look up the partition
loadState();
Partition p = PartitionManager.IT.getPartition(partition_name);
- if ( p == null )
+ if ( p == null ) {
throw new CommandFailedException("Partition " + partition_name + " does not exist.");
+ }
// Check if this partition belongs to the VDM
- if (p.isXeno() && !force)
+ if (p.isXeno() && !force) {
throw new CommandFailedException("Refusing to add partition as it is already allocated to the virtual disk manager. Use -f if you are sure.");
+ }
String output = new CommandPartitionAdd( p, chunksize ).execute();
- if ( output != null )
+ if ( output != null ) {
System.out.println( output );
-
+ }
saveState();
}
}
public String getUsage() {
- return "[-f] [-p<partition_name>] [-c<chunk_size>]";
+ return "-p<partition_name> [-f] [-c<chunk_size>]";
}
public String getHelpText() {
import org.xenoserver.control.PartitionManager;
public class ParsePartitionsList extends CommandParser {
- public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
- loadState();
- Iterator i = PartitionManager.IT.iterator();
- int idx = 1;
- System.out.println( " maj:min " + " blocks " + "start sect " +
- " num sects " + "name" );
- while (i.hasNext()) {
- Partition p = (Partition) i.next();
-
- if (p.isXeno()) {
- System.out.print("[ ");
- } else {
- System.out.print(" ");
- }
- System.out.print(Library.format(idx++, 2, false) + " ");
- System.out.print(Library.format(p.getMajor(),3,false) + ":" +
- Library.format(p.getMinor(),3,true) + " " +
- Library.format(p.getBlocks(),10,false) + " " +
- Library.format(p.getStartSect(),10,false) + " " +
- Library.format(p.getNumSects(),10,false) + " " +
- Library.format(p.getName(),7,true));
- if (p.isXeno()) {
- System.out.println("]");
- } else {
- System.out.println();
- }
+ public void parse(Defaults d, LinkedList args)
+ throws ParseFailedException, CommandFailedException {
+ loadState();
+ Iterator i = PartitionManager.IT.iterator();
+ int idx = 1;
+ System.out.println(
+ " maj:min "
+ + " blocks "
+ + "start sect "
+ + " num sects "
+ + "name");
+ while (i.hasNext()) {
+ Partition p = (Partition) i.next();
+
+ if (p.isXeno()) {
+ System.out.print("[ ");
+ } else {
+ System.out.print(" ");
+ }
+ System.out.print(Library.format(idx++, 2, false) + " ");
+ System.out.print(
+ Library.format(p.getMajor(), 3, false)
+ + ":"
+ + Library.format(p.getMinor(), 3, true)
+ + " "
+ + Library.format(p.getBlocks(), 10, false)
+ + " "
+ + Library.format(p.getStartSect(), 10, false)
+ + " "
+ + Library.format(p.getNumSects(), 10, false)
+ + " "
+ + Library.format(p.getName(), 7, true));
+ if (p.isXeno()) {
+ System.out.println("]");
+ } else {
+ System.out.println();
+ }
+ }
}
- }
- public String getName() {
- return "list";
- }
+ public String getName() {
+ return "list";
+ }
- public String getUsage() {
- return "";
- }
+ public String getUsage() {
+ return "";
+ }
- public String getHelpText() {
- return "List real partition information";
- }
+ public String getHelpText() {
+ return "List physical partition information. Partitions surrounded by [] are XenoPartitions.";
+ }
}
String partition_name = getStringParameter(args, 'p', "");
boolean write = getFlagParameter(args, 'w');
- if (domain_id == 0)
+ if (domain_id == 0) {
throw new ParseFailedException("Expected -n<domain_id>");
- if (partition_name.equals(""))
+ }
+ if (partition_name.equals("")) {
throw new ParseFailedException("Expected -p<partition_name>");
+ }
Mode mode;
- if (write)
+ if (write) {
mode = Mode.READ_WRITE;
- else
+ } else {
mode = Mode.READ_ONLY;
+ }
// Initialise the partition manager and look up the partition
loadState();
Partition p = PartitionManager.IT.getPartition(partition_name);
- if ( p == null )
+ if ( p == null ) {
throw new CommandFailedException("Partition " + partition_name + " does not exist.");
+ }
// Check if this partition belongs to the VDM
- if (p.isXeno() && !force)
+ if (p.isXeno() && !force) {
throw new CommandFailedException("Refusing to grant physical access as the given partition is allocated to the virtual disk manager. Use -f if you are sure.");
-
+ }
+
String output = new CommandPhysicalGrant( d, domain_id, p, mode ).execute();
- if ( output != null )
+ if ( output != null ) {
System.out.println( output );
+ }
}
public String getName() {
}
public String getUsage() {
- return "[-f] [-w] [-n<domain_id>] [-p<partition_name>]";
+ return "-n<domain_id> -p<partition_name> [-f] [-w]";
}
public String getHelpText() {
import org.xenoserver.control.PartitionManager;
public class ParsePhysicalList extends CommandParser {
+ public void parse(Defaults d, LinkedList args)
+ throws ParseFailedException, CommandFailedException {
+ int domain_id = getIntParameter(args, 'n', 0);
+ if (domain_id == 0) {
+ throw new ParseFailedException("Expected -n<domain_id>");
+ }
- public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
- int domain_id = getIntParameter(args, 'n', 0);
- if (domain_id == 0)
- throw new ParseFailedException("Expected -n<domain_id>");
+ // Initialise the partition manager
+ loadState();
- // Initialise the partition manager
- loadState();
-
- CommandPhysicalList list = new CommandPhysicalList( d, domain_id );
- String output = list.execute();
- if ( output != null )
- System.out.println( output );
-
- System.out.println( "maj:min " + " blocks " + "start sect " +
- " num sects " + "name " + "access" );
- Iterator i = list.extents().entrySet().iterator();
- while ( i.hasNext() )
- {
- Entry entry = (Entry) i.next();
- Extent e = (Extent) entry.getKey();
- String mode = entry.getValue().toString();
- Partition p = PartitionManager.IT.getPartition( e );
- if ( p != null ) {
- System.out.println(Library.format(p.getMajor(),3,false) + ":" +
- Library.format(p.getMinor(),3,true) + " " +
- Library.format(p.getBlocks(),10,false) + " " +
- Library.format(p.getStartSect(),10,false) + " " +
- Library.format(p.getNumSects(),10,false) + " " +
- Library.format(p.getName(),7,true) + " " +
- Library.format(mode,2,true));
- } else {
- System.out.println(Library.format(e.getMajor(),3,false) + ":" +
- Library.format(e.getMinor(),3,true) + " " +
- " " + " " +
- Library.format(e.getOffset(),10,false) + " " +
- Library.format(e.getSize(),10,false) + " " +
- " " + " " +
- Library.format(mode,2,true));
- }
+ CommandPhysicalList list = new CommandPhysicalList(d, domain_id);
+ String output = list.execute();
+ if (output != null) {
+ System.out.println(output);
+ }
+
+ System.out.println(
+ "maj:min "
+ + " blocks "
+ + "start sect "
+ + " num sects "
+ + "name "
+ + "access");
+ Iterator i = list.extents().entrySet().iterator();
+ while (i.hasNext()) {
+ Entry entry = (Entry) i.next();
+ Extent e = (Extent) entry.getKey();
+ String mode = entry.getValue().toString();
+ Partition p = PartitionManager.IT.getPartition(e);
+ if (p != null) {
+ System.out.println(
+ Library.format(p.getMajor(), 3, false)
+ + ":"
+ + Library.format(p.getMinor(), 3, true)
+ + " "
+ + Library.format(p.getBlocks(), 10, false)
+ + " "
+ + Library.format(p.getStartSect(), 10, false)
+ + " "
+ + Library.format(p.getNumSects(), 10, false)
+ + " "
+ + Library.format(p.getName(), 7, true)
+ + " "
+ + Library.format(mode, 2, true));
+ } else {
+ System.out.println(
+ Library.format(e.getMajor(), 3, false)
+ + ":"
+ + Library.format(
+ e.getMinor() | e.getPartitionNo(),
+ 3,
+ true)
+ + " "
+ + " "
+ + " "
+ + Library.format(e.getOffset(), 10, false)
+ + " "
+ + Library.format(e.getSize(), 10, false)
+ + " "
+ + " "
+ + " "
+ + Library.format(mode, 2, true));
+ }
+ }
}
- }
- public String getName() {
- return "list";
- }
+ public String getName() {
+ return "list";
+ }
- public String getUsage() {
- return "[-n<domain_id>]";
- }
+ public String getUsage() {
+ return "-n<domain_id>";
+ }
- public String getHelpText() {
- return "List all physical access which the given domain has been granted.";
- }
+ public String getHelpText() {
+ return "List all physical access which the given domain has been granted.";
+ }
}
import org.xenoserver.control.PartitionManager;
public class ParsePhysicalRevoke extends CommandParser {
- public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
- int domain_id = getIntParameter(args, 'n', 0);
- String partition_name = getStringParameter(args, 'p', "");
-
- if (domain_id == 0)
- throw new ParseFailedException("Expected -n<domain_id>");
- if (partition_name.equals(""))
- throw new ParseFailedException("Expected -p<partition_name>");
-
- // Initialise the partition manager and look up the partition
- loadState();
- Partition p = PartitionManager.IT.getPartition(partition_name);
-
- if ( p == null )
- throw new CommandFailedException("Partition " + partition_name + " does not exist.");
-
- String output = new CommandPhysicalRevoke( d, domain_id, p ).execute();
- if ( output != null )
- System.out.println( output );
- }
-
- public String getName() {
- return "revoke";
- }
-
- public String getUsage() {
- return "[-n<domain_id>] [-p<partition_name>]";
- }
-
- public String getHelpText() {
- return "Revoke access to the given partition from the specified domain.";
- }
+ public void parse(Defaults d, LinkedList args)
+ throws ParseFailedException, CommandFailedException {
+ int domain_id = getIntParameter(args, 'n', 0);
+ String partition_name = getStringParameter(args, 'p', "");
+
+ if (domain_id == 0) {
+ throw new ParseFailedException("Expected -n<domain_id>");
+ }
+ if (partition_name.equals("")) {
+ throw new ParseFailedException("Expected -p<partition_name>");
+ }
+
+ // Initialise the partition manager and look up the partition
+ loadState();
+ Partition p = PartitionManager.IT.getPartition(partition_name);
+
+ if (p == null) {
+ throw new CommandFailedException(
+ "Partition " + partition_name + " does not exist.");
+ }
+
+ String output = new CommandPhysicalRevoke(d, domain_id, p).execute();
+ if (output != null) {
+ System.out.println(output);
+ }
+ }
+
+ public String getName() {
+ return "revoke";
+ }
+
+ public String getUsage() {
+ return "-n<domain_id> -p<partition_name>";
+ }
+
+ public String getHelpText() {
+ return "Revoke access to the given partition from the specified domain.";
+ }
}
package org.xenoserver.cmdline;
+import java.text.DateFormat;
+import java.text.ParseException;
import java.util.Date;
import java.util.LinkedList;
import org.xenoserver.control.Settings;
public class ParseVdCreate extends CommandParser {
- public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
- String name = getStringParameter(args,'n',"");
- String size_s = getStringParameter(args,'s',"");
- String expiry_s = getStringParameter(args,'e',"");
- Date expiry;
-
- if ( name.equals("") )
- throw new ParseFailedException("Expected -n<name>");
- if ( size_s.equals("") )
- throw new ParseFailedException("Expected -s<size>");
- if ( expiry_s.equals("") )
- expiry = null;
- else
- expiry = new Date(Date.parse(expiry_s));
-
- long size = Library.parseSize(size_s);
-
- loadState();
- String output = new CommandVdCreate(name,size/Settings.SECTOR_SIZE,expiry).execute();
- if ( output != null )
- System.out.println( output );
- saveState();
- }
-
- public String getName() {
- return "create";
- }
-
- public String getUsage() {
- return "[-n<name>] [-s<size>] [-e<expiry>]";
- }
-
- public String getHelpText() {
- return "Create a new virtual disk with the specified parameters";
- }
+ public void parse(Defaults d, LinkedList args)
+ throws ParseFailedException, CommandFailedException {
+ String name = getStringParameter(args, 'n', "");
+ String size_s = getStringParameter(args, 's', "");
+ String expiry_s = getStringParameter(args, 'e', "");
+ Date expiry;
+
+ if (name.equals("")) {
+ throw new ParseFailedException("Expected -n<name>");
+ }
+ if (size_s.equals("")) {
+ throw new ParseFailedException("Expected -s<size>");
+ }
+ if (expiry_s.equals("")) {
+ expiry = null;
+ } else {
+ DateFormat format = DateFormat.getDateTimeInstance();
+ try {
+ expiry = format.parse(expiry_s);
+ } catch (ParseException e) {
+ throw new ParseFailedException("Could not parse date");
+ }
+ }
+
+ long size = Library.parseSize(size_s);
+
+ loadState();
+ String output =
+ new CommandVdCreate(name, size / Settings.SECTOR_SIZE, expiry)
+ .execute();
+ if (output != null) {
+ System.out.println(output);
+ }
+ saveState();
+ }
+
+ public String getName() {
+ return "create";
+ }
+
+ public String getUsage() {
+ return "-n<name> -s<size> [-e<expiry>]";
+ }
+
+ public String getHelpText() {
+ return "Create a new virtual disk with the specified parameters";
+ }
}
import org.xenoserver.control.VirtualDiskManager;
public class ParseVdDelete extends CommandParser {
- public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
- String vd_key = getStringParameter(args,'k',"");
-
- if ( vd_key.equals("") )
- throw new ParseFailedException("Expected -k<key>");
-
- loadState();
- if ( VirtualDiskManager.IT.getVirtualDisk(vd_key) == null )
- throw new CommandFailedException("Virtual disk " + vd_key + " does not exist");
-
- String output = new CommandVdDelete(vd_key).execute();
- if ( output != null )
- System.out.println( output );
-
- saveState();
- }
-
- public String getName() {
- return "delete";
- }
-
- public String getUsage() {
- return "[-k<key>]";
- }
-
- public String getHelpText() {
- return "Deletes the virtual disk with the specified key.";
- }
+ public void parse(Defaults d, LinkedList args)
+ throws ParseFailedException, CommandFailedException {
+ String vd_key = getStringParameter(args, 'k', "");
+
+ if (vd_key.equals("")) {
+ throw new ParseFailedException("Expected -k<key>");
+ }
+
+ loadState();
+ if (VirtualDiskManager.IT.getVirtualDisk(vd_key) == null) {
+ throw new CommandFailedException(
+ "Virtual disk " + vd_key + " does not exist");
+ }
+
+ String output = new CommandVdDelete(vd_key).execute();
+ if (output != null) {
+ System.out.println(output);
+ }
+
+ saveState();
+ }
+
+ public String getName() {
+ return "delete";
+ }
+
+ public String getUsage() {
+ return "-k<key>";
+ }
+
+ public String getHelpText() {
+ return "Deletes the virtual disk with the specified key.";
+ }
}
import org.xenoserver.control.VirtualDiskManager;
public class ParseVdFree extends CommandParser {
- public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
- boolean verbose = getFlagParameter(args, 'v');
-
- loadState();
- VirtualDisk free = VirtualDiskManager.IT.getFreeDisk();
- System.out.println( "Free disk has " + free.getExtentCount() + " extents totalling "
- + Library.formatSize(free.getSize()*Settings.SECTOR_SIZE,8,true) );
- if ( verbose ) {
- Iterator i = free.extents();
- System.out.println(" disk offset size");
- while (i.hasNext()) {
- Extent e = (Extent) i.next();
- System.out.println( Library.format(e.getDisk(), 6, false) + " "
- + Library.format(e.getOffset(), 12, false) + " "
- + Library.format(e.getSize(), 12, false) );
- }
+ public void parse(Defaults d, LinkedList args)
+ throws ParseFailedException, CommandFailedException {
+ boolean verbose = getFlagParameter(args, 'v');
+
+ loadState();
+ VirtualDisk free = VirtualDiskManager.IT.getFreeDisk();
+ System.out.println(
+ "Free disk has "
+ + free.getExtentCount()
+ + " extents totalling "
+ + Library.formatSize(
+ free.getSize() * Settings.SECTOR_SIZE,
+ 8,
+ true));
+ if (verbose) {
+ Iterator i = free.extents();
+ System.out.println(" disk offset size");
+ while (i.hasNext()) {
+ Extent e = (Extent) i.next();
+ System.out.println(
+ Library.format(e.getDisk(), 6, false)
+ + " "
+ + Library.format(e.getOffset(), 12, false)
+ + " "
+ + Library.format(e.getSize(), 12, false));
+ }
+ }
}
- }
- public String getName() {
- return "free";
- }
+ public String getName() {
+ return "free";
+ }
- public String getUsage() {
- return "[-v]";
- }
+ public String getUsage() {
+ return "[-v]";
+ }
- public String getHelpText() {
- return "Show free space allocated to virtual disk manager. -v enables verbose output.";
- }
+ public String getHelpText() {
+ return "Show free space allocated to virtual disk manager. -v enables verbose output.";
+ }
}
package org.xenoserver.cmdline;
+import java.text.DateFormat;
+import java.text.ParseException;
import java.util.Date;
import java.util.LinkedList;
import org.xenoserver.control.Defaults;
public class ParseVdRefresh extends CommandParser {
- public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
- String vd_key = getStringParameter(args,'k',"");
- String expiry_s = getStringParameter(args,'e',"");
- Date expiry;
-
- if ( vd_key.equals("") )
- throw new ParseFailedException("Expected -k<key>");
- if ( expiry_s.equals("") )
- expiry = null;
- else
- expiry = new Date(Date.parse(expiry_s));
-
- loadState();
- String output = new CommandVdRefresh(vd_key,expiry).execute();
- if ( output != null )
- System.out.println(output);
- saveState();
- }
-
- public String getName() {
- return "refresh";
- }
-
- public String getUsage() {
- return "-k<key> [-e<expiry>]";
- }
-
- public String getHelpText() {
- return "Refresh the expiry for the specified virtual disk. Omitting -e will cause the disk to never expire.";
- }
+ public void parse(Defaults d, LinkedList args)
+ throws ParseFailedException, CommandFailedException {
+ String vd_key = getStringParameter(args, 'k', "");
+ String expiry_s = getStringParameter(args, 'e', "");
+ Date expiry;
+
+ if (vd_key.equals("")) {
+ throw new ParseFailedException("Expected -k<key>");
+ }
+ if (expiry_s.equals("")) {
+ expiry = null;
+ } else {
+ DateFormat format = DateFormat.getDateTimeInstance();
+ try {
+ expiry = format.parse(expiry_s);
+ } catch (ParseException e) {
+ throw new ParseFailedException("Could not parse date");
+ }
+ }
+
+ loadState();
+ String output = new CommandVdRefresh(vd_key, expiry).execute();
+ if (output != null) {
+ System.out.println(output);
+ }
+ saveState();
+ }
+
+ public String getName() {
+ return "refresh";
+ }
+
+ public String getUsage() {
+ return "-k<key> [-e<expiry>]";
+ }
+
+ public String getHelpText() {
+ return "Refresh the expiry for the specified virtual disk. Omitting -e will cause the disk to never expire.";
+ }
}
while ( i.hasNext() ) {
VirtualDisk vd = (VirtualDisk) i.next();
System.out.print( vd.getKey() + " " );
- if ( vd.getExpiry() != null )
+ if ( vd.getExpiry() != null ) {
System.out.print( vd.getExpiry().toString() );
- else
+ } else {
System.out.print( " " );
+ }
System.out.println( " " + Library.format(vd.getName(),16,true) + " "
+ Library.formatSize(vd.getSize()*Settings.SECTOR_SIZE,8,false) );
}
} else {
VirtualDisk vd = VirtualDiskManager.IT.getVirtualDisk(key);
- if ( vd == null )
+ if ( vd == null ) {
throw new CommandFailedException("There is no virtual disk " + key );
+ }
System.out.println(" name: " + vd.getName());
System.out.println(" key: " + vd.getKey());
System.out.println(" size: " + Library.formatSize(vd.getSize()*Settings.SECTOR_SIZE,8,true));
- if ( vd.getExpiry() != null )
+ if ( vd.getExpiry() != null ) {
System.out.println("expiry: " + vd.getExpiry());
+ }
System.out.println();
Iterator i = vd.extents();
}
public String getUsage() {
- return "[-n<diskno>]";
+ return "[-k<key>]";
}
public String getHelpText() {
- return "Show a summary of all virtual disks, or details of one disk if -n is given";
+ return "Show a summary of all virtual disks, or details of one disk if -k is given";
}
}
outline = in.readLine();
while (outline != null) {
int disk = -1;
+ int partition_no = -1;
long offset = -1;
long size = -1;
StringTokenizer st = new StringTokenizer(outline);
if (st.hasMoreTokens()) {
- disk = Short.parseShort(st.nextToken(), 16);
+ disk = Integer.parseInt(st.nextToken(), 16);
+ }
+ if (st.hasMoreTokens()) {
+ partition_no = Integer.parseInt(st.nextToken(), 16);
}
if (st.hasMoreTokens()) {
offset = Long.parseLong(st.nextToken(), 16);
}
if (st.hasMoreTokens()) {
String mode = st.nextToken();
- Extent extent = new Extent(disk, offset, size);
+ Extent extent = new Extent(disk, offset, size, partition_no);
if (mode.equals("rw")) {
map.put(extent, Mode.READ_WRITE);
} else if (mode.equals("r")) {
Extent extent =
new Extent(
partition.getDisk(),
- extentSize,
- partition.getStartSect() + (extentSize * loop));
+ partition.getStartSect() + (extentSize * loop),
+ extentSize);
addExtent(extent);
}
XMLHelper.getSubNode("disk", enode))),
Long.parseLong(
XMLHelper.getText(
- XMLHelper.getSubNode("size", enode))),
- Long.parseLong(
- XMLHelper.getText(
- XMLHelper.getSubNode("offset", enode))));
+ XMLHelper.getSubNode("offset", enode))),
+ Long.parseLong(
+ XMLHelper.getText(
+ XMLHelper.getSubNode("size", enode))));
+
vd.addExtent(extent);
}
}